package com.qunar.im.ui.view.baseView.processor;


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.qunar.im.base.module.IMMessage;
import com.qunar.im.ui.R;
import com.qunar.im.ui.custommessage.TransferBean;
import com.qunar.im.ui.util.MoneyUtils;
import com.qunar.im.ui.view.baseView.IMessageItem;
import com.qunar.im.ui.view.bubbleLayout.BubbleLayout;

public class CustomProcessor extends DefaultMessageProcessor {


    @Override
    public void processChatView(ViewGroup parent, IMessageItem item) {
        LayoutInflater inflater = LayoutInflater.from(item.getContext());
        View inflate = inflater.inflate(R.layout.chat_change_money, null);

        RelativeLayout mRlChangeMoneyBg = (RelativeLayout) inflate.findViewById(R.id.rl_change_money_bg);
        TextView mTvChangeMoneyNum = (TextView) inflate.findViewById(R.id.tv_change_money_num);
        TextView mTvChangeMoneyMark = (TextView) inflate.findViewById(R.id.tv_change_money_mark);
        IMMessage message = item.getMessage();
        String ext = message.getExt();

        try {
            TransferBean transferBean = new Gson().fromJson(ext, TransferBean.class);
            if (transferBean != null) {
                String s = "¥" + MoneyUtils.getMoney(Integer.valueOf(transferBean.money));
                mTvChangeMoneyNum.setText(s);
            }

        } catch (Exception e) {
            mTvChangeMoneyNum.setText("????");
        }
        if (message.getDirection() == IMMessage.DIRECTION_SEND) {
            mRlChangeMoneyBg.setBackgroundResource(R.drawable.bg_chat_change_money_right);
        } else if (message.getDirection() == IMMessage.DIRECTION_RECV) {
            mRlChangeMoneyBg.setBackgroundResource(R.drawable.bg_chat_change_money_left);
        }

//        QIMSdk.getInstance()
//        message.getFromID().equals(QIMSdk.getInstance())
        parent.addView(inflate);

    }

    @Override
    public void processBubbleView(BubbleLayout bubbleLayout, IMessageItem item) {
        super.processBubbleView(bubbleLayout, item);
        bubbleLayout.noBubbleStyle();
    }

}
